package com.example.ck.controller;


import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.example.ck.entity.Cooperate;
import com.example.ck.entity.User;
import com.example.ck.service.CooperateService;
import com.example.ck.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Cooperate)表控制层
 *
 * @author makejava
 * @since 2024-05-10 11:53:05
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("cooperate")
public class CooperateController {
    @Autowired
    private CooperateService cooperateService;

    /**
     * 获取所有的合作信息
     */
    @GetMapping()
    private ResultVo getAllCooperate() {
        List<Cooperate> allCooperate = cooperateService.getAllCooperate();
        return new ResultVo<>(allCooperate);
    }

    /**
     * 添加合作伙伴
     */
    @PostMapping("/add")
    private ResultVo addCooperate(@RequestBody Cooperate cooperate) {
        boolean b = cooperateService.addCooperate(cooperate);
        if (b) {
            return new ResultVo("添加成功", true, cooperate);
        } else {
            return new ResultVo("添加失败", false, null);
        }
    }

    /**
     * 根据id删除合作伙伴
     */
    @DeleteMapping
    private ResultVo removeCooperate(@RequestParam Integer hzId) {
        boolean b = cooperateService.removeCooperate(hzId);
        if (b) {
            return new ResultVo(200,"移除成功", true, null);
        } else {
            return new ResultVo(201,"移除失败", false, null);
        }

    }

}

